﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class BookDoc : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private int int_1 = 0;
        protected Label labBookTitle;
        protected Label labContent;
        protected Label labTip;
        private PublicFun publicFun_0 = new PublicFun();

        private string method_0()
        {
            string str = "";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select ItemName,ID from BookItem where SubjectID=" + this.int_0.ToString() + " and UPID=0 order by SortInfo,ID", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                str = str + "<a href='BookDoc.aspx?SubjectID=" + this.int_0.ToString() + "&ID=" + reader["ID"].ToString() + "'>" + reader["Itemname"].ToString() + "</a><br>";
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            return str;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---查看电子教材";
                this.int_0 = Convert.ToInt32(base.Request["SubjectID"].ToString());
                this.int_1 = Convert.ToInt32(base.Request["ID"].ToString());
                if (!base.IsPostBack)
                {
                    this.labTip.Text = string.Concat(new object[] { "<a href='#' onclick=javascript:myStudyLog('", this.int_0, "');><img src='../image/menuico/Menu17.gif' border=0></img> <font color=blue>我的笔记</font></a>&nbsp;<a href='#' onclick=javascript:heStudyLog('", this.int_0, "');><img src='../image/menuico/MenuTE.gif' border=0></img> <font color='#ff6600'>他人笔记</font></a>&nbsp;<a href='FrmForumStudy.aspx?Flag=B&ID=", this.int_0, "' target=_blank><img src='../image/menuico/Menu287.gif' border=0></img> <font color=green>讨论交流</font></a>" });
                    string str4 = "0";
                    string str6 = "0";
                    string str5 = "";
                    string str = "";
                    string str2 = "0";
                    string cmdText = "";
                    if (this.int_1 == 0)
                    {
                        cmdText = string.Concat(new object[] { "select '' as ItemContent,'' as ItemName,'0' as ZJFen,a.FenValue,a.RemoveFen,a.SubjectName from BookInfo a,TypeList b where b.ID=a.SubjectTypeID and (b.BrowUserCode like '%,", this.httpCookie_0.Value, ",%' or b.BrowUserCode like '%,所有人员,%'  or b.BrowDeptID like '%,", this.httpCookie_3.Value, ",%' or b.BrowDeptName like '%,所有部门,%' ) and a.ID=", this.int_0 });
                    }
                    else
                    {
                        cmdText = string.Concat(new object[] { "select b.ItemContent,b.ItemName,b.FenValue as ZJFen,a.FenValue,a.RemoveFen,a.SubjectName from BookInfo a,BookItem b,TypeList c where  c.ID=a.SubjectTypeID and (c.BrowUserCode like '%,", this.httpCookie_0.Value, ",%' or c.BrowUserCode like '%,所有人员,%'  or c.BrowDeptID like '%,", this.httpCookie_3.Value, ",%' or c.BrowDeptName like '%,所有部门,%' ) and b.SubjectID=a.ID and b.ID=", this.int_1, " and a.ID=", this.int_0 });
                    }
                    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                    connection.Open();
                    SqlCommand command = new SqlCommand(cmdText, connection);
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    if (reader.Read())
                    {
                        str4 = reader["FenValue"].ToString();
                        str6 = reader["RemoveFen"].ToString();
                        str5 = reader["SubjectName"].ToString();
                        str = reader["ItemName"].ToString();
                        str2 = reader["ZJFen"].ToString();
                        this.labContent.Text = reader["ItemContent"].ToString();
                        if (!(str.Trim() != ""))
                        {
                            this.labBookTitle.Text = str5;
                            this.labContent.Text = this.method_0();
                        }
                        else
                        {
                            this.labBookTitle.Text = str;
                        }
                    }
                    reader.Close();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                    if (str4.Trim() == "")
                    {
                        str4 = "0";
                    }
                    if (str6.Trim() == "")
                    {
                        str6 = "0";
                    }
                    if (this.publicFun_0.GetValues("select a.UserCode  from UserInfo a,MemberLevel b where getdate()>DateAdd(dd,b.RemoveValue,Convert(dateTime,a.UpdateTime)) and a.UserMember=b.ID and a.UserCode='" + this.httpCookie_0.Value + "' and LevelRemove='C'", "UserCode") == "")
                    {
                        if (this.publicFun_0.GetValues(string.Concat(new object[] { "select ID from UserStudyFen where UserCode='", this.httpCookie_0.Value, "' and ExamorStudy='B' and Formtable='BookInfo' and FormID=", this.int_0 }), "ID").Trim() == "")
                        {
                            if (this.publicFun_0.OpertionMemberFen(this.httpCookie_0.Value, Convert.ToInt32(str6)))
                            {
                                double num = 0.0;
                                num = Convert.ToDouble(str4);
                                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "delete  UserStudyFen where ExamOrStudy='B' and UserCode='", this.httpCookie_0.Value, "' and Formtable='BookInfo' and FormID=", this.int_0, ";insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", str5, "','", num, "','BookInfo','", this.int_0, "','B')" }));
                            }
                            else
                            {
                                this.labContent.Text = "";
                                base.Response.Write("<script>alert('会员积分不足,充值方可进行查看电子教材！');window.close();</script>");
                                return;
                            }
                        }
                        if ((this.int_1 != 0) && (this.publicFun_0.GetValues(string.Concat(new object[] { "select ID from UserStudyFen where UserCode='", this.httpCookie_0.Value, "' and ExamorStudy='Z' and Formtable='BookItem' and FormID=", this.int_1 }), "ID").Trim() == ""))
                        {
                            if (str2.Trim() == "")
                            {
                                str2 = "0";
                            }
                            this.publicFun_0.GetValues(string.Concat(new object[] { "insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", str, "','", str2, "','BookItem','", this.int_1, "','Z')" }));
                        }
                    }
                    else
                    {
                        this.publicFun_0.ExecuteSql("update UserInfo set UserFen=0 where UserCode='" + this.httpCookie_0.Value + "'");
                        this.labContent.Text = "";
                        base.Response.Write("<script>alert('会员积分不足,充值方可进行查看电子教材！');window.close();</script>");
                    }
                }
            }
        }
    }
}

